#coding:utf-8
'''输出答应
'''
import sys,types,json
from scrapy.conf import settings
def print_msg(text):
    if sys.platform=="win32":
        defaultencode="gbk"
    else:
        defaultencode="utf8"
    #编辑器运行
    output=settings["PRINT_CONSOLE"]
    if output:
        if type(text)==types.DictType:
            print json.dumps(text,ensure_ascii=False,encoding=defaultencode)
        elif type(text)==types.ListType:
            print text
        elif type(text)==types.NoneType:
            print text
        elif type(text)==types.StringType:
            print text.decode("utf8").encode(defaultencode)
        
    else:
        print text
    #控制台运行
    
def unicode_to_str(unicodestr,encode="utf8"):
    if type(unicodestr)==types.UnicodeType:
        return unicodestr.encode(encode)
    else:
        return unicodestr

if __name__=="__main__":
    url=u"小时"
    print_msg("熊先华 :%s" % unicode_to_str(url))
    
